/*
 * Títutlo: DequeDoubleList.java
 * Autor: Diego Serafín Martínez García
 * Descripción: Estructura de Datos, "Deque", implementada con DoubleList.
 * 
 * Universidad Autónoma de Yucatán
 * 
 */

package aerodromo.util.estructurasDatos.deque;

import aerodromo.util.estructurasDatos.lista.DoublyList;
import aerodromo.util.estructurasDatos.lista.DoublyListNode;

/**
 *
 * @author Diego Martínez García
 */
public class DequeDoubleList<T>
        implements Deque<T>{

    
    
    private DoublyList<T> doubleList;

    public DequeDoubleList(){
       
       doubleList = new DoublyList<T>();
    }


    @Override
    public int size() {
        return doubleList.size();
    }

    @Override
    public boolean isEmpty() {
        return doubleList.isEmpty();
    }

    @Override
    public void insertFirst(T o) {
        doubleList.insertAtFirst(o);
    }

    @Override
    public void insertLast(T o) {
        doubleList.insertAtLast(o);
    }

    @Override
    public T removeFirst() throws DequeEmptyException {
        T objeto = doubleList.removeFromFisrt();
        return objeto;
    }

    @Override
    public T removeLast() throws DequeEmptyException {
        T objeto = doubleList.removeFromLast();
        return objeto;
    }

    @Override
    public T first() throws DequeEmptyException {
        return doubleList.getFirstNode().getData();
    }

    @Override
    public T last() throws DequeEmptyException {
       return doubleList.getLastNode().getData();
    }

    @Override
    public T obtenerIndice(int i) {
        
        DoublyListNode<T> current;
        current = (DoublyListNode<T>)doubleList.getLastNode();
        while(i!=0){
            current=current.getPrev();
            i--;
        }
        return (T) current;
    }


}
